<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        header{
            padding: 30px;
            border: 1px solid #000;
            position: relative;
        }
        div{
            height: 100px;
            width: 100px;
            background-color: red;
            border-left: 15px solid #000;
        }
    </style>
</head>
<body>
    <header>
        <div></div>
    </header>
    <script>
        var div = document.querySelector("div");
        div.onclick = function(){
            // 获取的是div到最近的设置有定位属性的父级标签的间距,到html为止
            console.log(div.offsetLeft);
            // 获取div左边边框的宽度
            console.log(div.clientLeft);
        }
    </script>
</body>
</html>